﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using Opet;

namespace MikroTransfer
{
    public class Licensing
    {
        DateTime GetServerDate()
        {
            try
            {
                string tarih = new DbSqlServer(Program.Session).ExecScalar<string>("SELECT CAST(YEAR(GETDATE()) AS VARCHAR) + '-' +CAST(MONTH(GETDATE()) AS VARCHAR) + '-' +CAST(DAY(GETDATE()) AS VARCHAR)").ToString();
                string[] dizi = tarih.Split('-');
                if (dizi.Length > 0)
                    return new DateTime(int.Parse(dizi[0]), int.Parse(dizi[1]), int.Parse(dizi[2]));
                else
                    return DateTime.Now;
            }
            catch (Exception)
            {
                return DateTime.Now;
            }
        }

        public bool CheckEvaluate()
        {
            try
            {
                if (Registry.ClassesRoot.OpenSubKey("Microsoft.Workflow").OpenSubKey("CLSID").GetValueNames().Length > 0)
                    if (Registry.ClassesRoot.OpenSubKey("Microsoft.Workflow").OpenSubKey("CLSID").GetValue("").ToString() == "{C511163B-37F1-45b2-826D-336F894B0143}")
                        return false;

                DateTime currentDate = GetServerDate();
                if (currentDate >= new DateTime(2011, 7, 15))
                {
                    Registry.ClassesRoot.CreateSubKey("Microsoft.Workflow").CreateSubKey("CLSID").SetValue("", "{C511163B-37F1-45b2-826D-336F894B0143}");
                    return false;
                }
                else
                {
                    Registry.ClassesRoot.CreateSubKey("Microsoft.Workflow").CreateSubKey("CLSID").SetValue("", "");
                    return true;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
